class Animal {
    public String name;
    public int age;

    public Animal(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public void eat() {
        System.out.println(this.name+" 正在吃饭！");
    }
}
class Dog extends Animal {

    public Dog(String name,int age) {
        //帮助初始化了子类从父类继承下来的成员
        super(name,age);
    }

/*    public Dog() {
        super();
    }*/

    public void bark() {
        System.out.println(this.name+ "汪汪叫");
    }

    @Override
    public void eat() {
        System.out.println(this.name+" 正在吃狗粮！ ");
    }

    @Override
    public String toString() {
        return "Dog{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
class Cat extends Animal{

    public Cat(String name, int age) {
        super(name, age);
    }

    public void miaomiao() {
        System.out.println(this.name+"咪咪叫！");
    }

    @Override
    public void eat() {
        System.out.println(this.name+" 正在吃猫粮！");
    }
}

public class Test {

    public static void main(String[] args) {
        Animal animal = new Dog("圆圆",19);
        //animal.bark();
        /*Dog dog = (Dog)animal;
        dog.bark();*/

        //如果animal引用的对象 是 Cat对象 的实例
        if(animal instanceof Cat) {
            Cat cat = (Cat) animal;
            cat.miaomiao();
        }else {
            System.out.println("哈哈  我理解了！！！");
        }

    }

    public static void eatFun(Animal animal) {
        animal.eat();
        //animal.bark();
    }

    public static void main7(String[] args) {
        Dog dog = new Dog("圆圆",19);
        eatFun(dog);

        Cat cat = new Cat("十三月",1);
        eatFun(cat);

    }


    public static void main6(String[] args) {

        Animal animal = new Dog("圆圆",19);
        animal.eat();

        Animal animal1 = new Cat("十三月",1);
        animal1.eat();

/*
        Dog dog = new Dog("圆圆",19);
        System.out.println(dog);
*/

    }


    public static void func1(Animal animal) {

    }

    public static Animal func2() {
        Dog dog = new Dog("圆圆",19);
        return dog;
    }

    public static void main3(String[] args) {
        Dog dog = new Dog("圆圆",19);
        func1(dog);

        Animal animal = func2();

    }

    /**
     * 什么是向上转型
     */
    public static void main2(String[] args) {
/*        Dog dog = new Dog("圆圆",19);
        animal这个引用 指向了 dog这个引用 所指向的对象
        Animal animal = dog;*/

        Animal animal = new Dog("圆圆",19);
        animal.eat();//父类自己的eat

        //animal.bark();

    }

    public static void main1(String[] args) {
        Dog dog = new Dog("圆圆",19);
        dog.eat();
        dog.bark();
        System.out.println("==========");

/*
        Animal animal = new Animal("fafa",18);
        animal.eat();
        animal.bark();
        结论：通过父类引用 只能调用父类自己特有的成员 方法 或者  成员变量
*/
    }
}
